package br.com.application.dao;

import br.com.application.pojos.Mensagens;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
//teste commit
public class DAOMessage {

	private SQLiteDatabase banco;
	
	public DAOMessage(SQLiteDatabase bancoMsg){
		this.banco = bancoMsg;
	}
	
	public Mensagens getMessage(){
		Mensagens message = null;
		String sql = "SELECT ID, TITULO, CONTEUDO, DATAINICIAL, DATAFINAL, LIDA FROM MESSAGES;";
		try{
			Cursor c = banco.rawQuery(sql, null);
			message = new Mensagens();
			while(c.moveToNext()){
				message.setLida(c.getInt(0));
				message.setTitulo(c.getString(1));
				message.setConteudo(c.getString(2));
				message.setDataInicial(c.getString(3));
				message.setDataFinal(c.getString(4));
				message.setLida(c.getInt(5));
			}
			c.close();
		}catch (Exception e) {
			e.printStackTrace();
		}finally{
			banco.close();
		}
		return message;
	}
	
	public boolean insert(Mensagens message){
		
		String insert =  " INSERT INTO MENSAGENS				 	";
			   insert += " (     									";
			   insert += " TITULO, 						 			";
			   insert += " CONTEUDO,       						 	";
			   insert += " DATAINICIAL,     						";
			   insert += " DATAFINAL,      						 	";
			   insert += " LIDA       						 		";
			   insert += " )           							 	";
			   insert += " VALUES        						 	";
			   insert += " (      		 						 	";
			   insert += "'"+message.getTitulo()+ "',			 	";
			   insert += "'"+message.getConteudo()+ "',			 	";
			   insert += ""+message.getDataInicial()+ "',	    	";
			   insert += ""+message.getDataFinal()+ "',             ";
			   insert += ""+message.getLida()+ "               		";
			   insert += " );     		                         	";
			   
			   try{
				   banco.execSQL(insert);
				   return true;
			   }catch (Exception e) {
				   e.printStackTrace();
				   return false;
			   }finally{
				   banco.close();
			   }
			   
	}
		
	public boolean delete(int Id){
		
	//	falta implementar	
	
		return true;
	}
}
